package com.kuzan.autocloud.client.sys.config;

import com.kuzan.autocloud.common.model.form.Form;
import com.kuzan.autocloud.common.model.form.FormField;
import com.kuzan.autocloud.common.model.report.Report;
import com.kuzan.autocloud.common.model.report.ReportField;
import com.kuzan.autocloud.common.repository.form.FormFieldRepository;
import com.kuzan.autocloud.common.repository.form.FormRepository;
import com.kuzan.autocloud.common.repository.report.ReportFieldRepository;
import com.kuzan.autocloud.common.repository.report.ReportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author kuzank
 */
@Service
public class InitializeHelper {

    @Autowired
    FormRepository formRepository;
    @Autowired
    FormFieldRepository formFieldRepository;
    @Autowired
    ReportRepository reportRepository;
    @Autowired
    ReportFieldRepository reportFieldRepository;


    public void addReportField(Report report, List<ReportField> fields) {

        reportRepository.save(report);

        fields.forEach(field -> {
            field.setReport(report.getId());
            reportFieldRepository.save(field);
        });
    }

    public void addFormField(Form form, List<FormField> formFields) {

        this.formRepository.save(form);

        formFields.forEach(item -> {
            item.setForm(form.getId());
            this.formFieldRepository.save(item);
        });
    }

}
